GSequence *children;
GHashTable *header_hash;
+ GtkWidget *placeholder;
+
GtkListBoxSortFunc sort_func;
gpointer sort_func_target;
GDestroyNotify sort_func_target_destroy_notify;
gtk_list_box_update_selected (list_box, row);
}
+
+/**
+ * gtk_list_box_set_placeholder:
+ * @list_box: a #GtkListBox
+ * @placeholder: (allow-none): a #GtkWidget or %NULL
+ *
+ * Sets the placeholder widget that is shown in the list when
+ * it doesn't display any visible children.
+ *
+ * Since: 3.10
+ */
+void
+gtk_list_box_set_placeholder (GtkListBox *list_box, GtkWidget *placeholder)
+{
+ GtkListBoxPrivate *priv = list_box->priv;
+
+ if (priv->placeholder)
+ {
+ gtk_widget_unparent (priv->placeholder);
+ gtk_widget_queue_resize (GTK_WIDGET (list_box));
+ }
+
+ priv->placeholder = placeholder;
+
+ if (placeholder)
+ {
+ gtk_widget_set_parent (GTK_WIDGET (placeholder), GTK_WIDGET (list_box));
+ gtk_widget_set_child_visible (GTK_WIDGET (placeholder),
+ priv->n_visible_rows == 0);
+ }
+}
+
+
/**
* gtk_list_box_set_adjustment:
* @list_box: a #GtkListBox
gtk_widget_set_window (GTK_WIDGET (list_box), window); /* Passes ownership */
}
+static void
+list_box_add_visible_rows (GtkListBox *list_box, int n)
+{
+ GtkListBoxPrivate *priv = list_box->priv;
+ int was_zero;
+
+ was_zero = priv->n_visible_rows == 0;
+ priv->n_visible_rows += n;
+
+ if (priv->placeholder &&
+ (was_zero || priv->n_visible_rows == 0))
+ gtk_widget_set_child_visible (GTK_WIDGET (priv->placeholder),
+ priv->n_visible_rows == 0);
+}
+
/* Children are visible if they are shown by the app (visible)
and not filtered out (child_visible) by the listbox */
static void
update_row_is_visible (GtkListBox *list_box, GtkListBoxRow *row)
{
- GtkListBoxPrivate *priv = list_box->priv;
gboolean was_visible;
was_visible = row->priv->visible;
gtk_widget_get_child_visible (GTK_WIDGET (row));
if (was_visible && !row->priv->visible)
- priv->n_visible_rows--;
+ list_box_add_visible_rows (list_box, -1);
if (!was_visible && row->priv->visible)
- priv->n_visible_rows++;
+ list_box_add_visible_rows (list_box, 1);
}
static gboolean
gtk_widget_set_child_visible (GTK_WIDGET (row), TRUE);
row->priv->visible = gtk_widget_get_visible (GTK_WIDGET (row));
if (row->priv->visible)
- priv->n_visible_rows++;
+ list_box_add_visible_rows (list_box, 1);
gtk_list_box_apply_filter (list_box, row);
if (gtk_widget_get_visible (GTK_WIDGET (list_box)))
{
}
if (row->priv->visible)
- priv->n_visible_rows--;
+ list_box_add_visible_rows (list_box, -1);
if (row->priv->header != NULL)
{
GSequenceIter *iter;
GtkListBoxRow *row;
+ if (priv->placeholder != NULL && include_internals)
+ callback (priv->placeholder, callback_target);
+
iter = g_sequence_get_begin_iter (priv->children);
while (!g_sequence_iter_is_end (iter))
{
minimum_height = 0;
+ if (priv->placeholder != NULL && gtk_widget_get_child_visible (priv->placeholder))
+ gtk_widget_get_preferred_height_for_width (priv->placeholder, width,
+ &minimum_height, NULL);
+
for (iter = g_sequence_get_begin_iter (priv->children);
!g_sequence_iter_is_end (iter);
iter = g_sequence_iter_next (iter))
minimum_width = 0;
natural_width = 0;
+ if (priv->placeholder != NULL && gtk_widget_get_child_visible (priv->placeholder))
+ gtk_widget_get_preferred_width (priv->placeholder,
+ &minimum_width, &natural_width);
+
for (iter = g_sequence_get_begin_iter (priv->children);
!g_sequence_iter_is_end (iter);
iter = g_sequence_iter_next (iter))
header_allocation.x = 0;
header_allocation.width = allocation->width;
+ if (priv->placeholder != NULL && gtk_widget_get_child_visible (priv->placeholder))
+ {
+ gtk_widget_get_preferred_height_for_width (priv->placeholder,
+ allocation->width, &child_min, NULL);
+ header_allocation.height = child_min;
+ header_allocation.y = child_allocation.y;
+ gtk_widget_size_allocate (priv->placeholder,
+ &header_allocation);
+ child_allocation.y += child_min;
+ }
+
for (iter = g_sequence_get_begin_iter (priv->children);
!g_sequence_iter_is_end (iter);
iter = g_sequence_iter_next (iter))